﻿using Developer.Code;
using Developer.Service;
using Super.Framework.Common.Web;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Developer.Web.Controllers
{
    public class CommentController : BaseController
    {
        // GET: Comment
        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public JsonResult ToComment()
        {
            var uid = Query.Value("uid").ToInt();
            var bid = Query.Value("bid").ToInt();
            var contents = Query.Value("contents");

            try {
                CommentService.Add(new Entity.Comments
                {
                    BookId = bid,
                    Contents = contents,
                    CreateTime = DateTime.Now,
                    IsAbort = false,
                    UserId = uid
                });
            }catch(Exception e)
            {
                return Json(new { error = 0 ,detail = e.ToString() }, JsonRequestBehavior.AllowGet);
            }
            return Json(new { success = 1 }, JsonRequestBehavior.AllowGet);
        }
    }
}